home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / addpcx.zip / VGRFILL.C < prev    next >
C/C++ Source or Header  |  1988-04-10  |  3KB  |  132 lines

  1. /*    VGRFILL.c - Routine to fill an outline in a bit map.
  2.  
  3. DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! 
  4. *****************************************************************************
  5. *                         NOTE CAREFULLY:                                *
  6. *****************************************************************************
  7. *               This function uses ***LOTS***                            *
  8. *         of stack space!!! ie: count on up to about 10K                 *
  9. *         for every 100 levels of call nesting, with a                   *
  10. *         possibility of >200 levels being reached!!!                    *
  11. *****************************************************************************
  12. DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! DANGER! 
  13. */
  14.  
  15.  
  16. #include "lib.h"
  17. #include "vgr.h"
  18.  
  19.  
  20. #ifdef __STDC__
  21. void vgr_fill(int x,int y,int color);
  22. static void _fill_y(int x,int y,int yinc);
  23. static void _fill_x(int x,int y);
  24. static int __fill_x(int x,int y,int xinc);
  25. #else
  26. void vgr_fill();
  27. static void _fill_y();
  28. static void _fill_x();
  29. static int __fill_x();
  30. #endif
  31.  
  32. static unsigned char _color, _search;
  33. static int _set_cnt, _up_cnt, _dn_cnt, _y_ok;
  34.  
  35.  
  36. void vgr_fill( x, y, color )
  37. int x, y, color;
  38. {
  39.     if ( (_search = VGR_GET( x, y )) == (_color = color) )
  40.        return;
  41.  
  42.     _fill_y( x, y+1,  1 );
  43.     _fill_y( x, y  , -1 );
  44. }
  45.  
  46.  
  47. static void _fill_y( x, y, yinc )
  48. int x, y, yinc;
  49. {
  50.     for ( ; y >= 0 && y < VGR_VRES; y += yinc )
  51.        if ( _search == VGR_GET( x, y ) )
  52.           _fill_x( x, y );
  53.        else return;
  54. }
  55.  
  56.  
  57. static void _fill_x( x, y )
  58. int x, y;
  59. {
  60.     int i, l, h, u, d, c;
  61.     void _fill_y();
  62.  
  63. #ifdef DEBUG
  64.     static int depth;
  65.     
  66.     putcur(0,0);
  67.     printf("%d  ", ++depth );
  68.     if ( constat() )
  69.        if ( conin() == 27 )
  70.        {  video_mode(3);
  71.           exit(1);
  72.        };
  73. #endif
  74.     _set_cnt = _up_cnt = _dn_cnt = 0;
  75.     _y_ok = ( (y >= 1) && (y < (VGR_VRES-1)) );
  76.  
  77.     h = __fill_x( x+1, y,  1 );
  78.     l = __fill_x( x  , y, -1 );
  79.  
  80.     /* The purpose of the following code is to prevent 
  81.        excessive call nesting. It can be removed, but 
  82.        the resulting several thousand useless function 
  83.        calls slow down processing considerably, as well 
  84.        as killing the system when SP rolls over...
  85.     */
  86.  
  87.     if ( !_y_ok )
  88.     {
  89. #ifdef DEBUG
  90.        depth--;
  91. #endif
  92.        return;
  93.     };
  94.  
  95.     c = _set_cnt;
  96.     u = _up_cnt;
  97.     d = _dn_cnt;
  98.  
  99.     if ( c != u )
  100.        for ( i = l+1; i <= h-1; i++ )
  101.           if ( _search == VGR_GET( i, y-1 ) )
  102.              _fill_y( i, y-1, -1 );
  103.  
  104.     if ( c != d )
  105.        for ( i = l+1; i <= h-1; i++ )
  106.           if ( _search == VGR_GET( i, y+1 ) )
  107.              _fill_y( i, y+1,  1 );
  108. #ifdef DEBUG
  109.     depth--;
  110. #endif
  111. }
  112.  
  113.  
  114. static int __fill_x( x, y, xinc )
  115. int x, y, xinc;
  116. {
  117.     for ( ; x >= 0 && x < VGR_HRES; x += xinc )
  118.        if ( _search == VGR_GET( x, y ) )
  119.        {  VGR_SET( x, y, _color ); 
  120.           _set_cnt++;
  121.  
  122.           if ( _y_ok )
  123.           {  if ( _search == VGR_GET(x,y-1) )
  124.                 _up_cnt++;
  125.              if ( _search == VGR_GET(x,y+1) )
  126.                 _dn_cnt++;
  127.           };
  128.        } else return x;
  129. }
  130.  
  131.  
  132.